package com.daiqile.myinterest.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.daiqile.myinterest.R;
import com.daiqile.myinterest.adapter.HeaderAdapter;
import com.daiqile.myinterest.customview.ObservableScrollView;
import com.daiqile.myinterest.model.HelpListDTO;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ScrollColorChangeActivity extends AppCompatActivity implements ObservableScrollView.OnObservableScrollViewScrollChanged {

    @BindView(R.id.s_img)
    ImageView sImg;
    @BindView(R.id.s_ll_title)
    LinearLayout sLlTitle;
    @BindView(R.id.o_scrollView)
    ObservableScrollView oScrollView;
    @BindView(R.id.o_title)
    TextView oTitle;
    @BindView(R.id.recycleView)
    RecyclerView recycleView;
    private int imageHeight;
    private int titleHeight;
    private HeaderAdapter adapter;
    private List<HelpListDTO> helpList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scroll_color_change);

        ButterKnife.bind(this);
        oScrollView.setOnObservableScrollViewScrollChanged(this);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recycleView.setLayoutManager(linearLayoutManager);
        adapter = new HeaderAdapter(null);
        recycleView.setAdapter(adapter);
        initHelpList();
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            imageHeight = sImg.getHeight();
            titleHeight = oTitle.getHeight();
            Log.d("imageHeight", String.valueOf(imageHeight));
            Log.d("titleHeight", String.valueOf(titleHeight));
        }

    }

    @Override
    public void onObservableScrollViewScrollChanged(int l, int t, int oldl, int oldt) {
        int height = imageHeight - titleHeight;
        if (t <= 0) {
            sLlTitle.setBackgroundColor(Color.argb(0, 30, 144, 255));
        } else if (t > 0 && t < height) {

            float a = (float) t / height;
            float b = (a * 255);
            sLlTitle.setBackgroundColor(Color.argb((int) b, 30, 144, 255));
        } else {
            sLlTitle.setBackgroundColor(Color.argb(255, 30, 144, 255));
        }
    }
    private void initHelpList() {
        for (int i =0;i<2 ;i++){
            HelpListDTO a = new HelpListDTO("1、还款方式","1)使用本人绑定银行卡还款\n2)支付宝知道还款账户;");
            helpList.add(a);
            HelpListDTO b = new HelpListDTO("2、申请条件","年满18-30周岁，非学生，本人实名制手机号码且连续使用时间满6个月以上即可尝试申请。");
            helpList.add(b);
            HelpListDTO c = new HelpListDTO("3、审核不通过原因","小草钱包系统是通过大数据分析自动审核，由于您的综合评分不足，因此借款申请暂未获得批准，如和人资料无重大变化，不想建议短期内再次申请");
            helpList.add(c);
            HelpListDTO d = new HelpListDTO("4、姓名或身份证填写有误","为了您的账号信息安全，暂时不可以修改，因为姓名和身份证明是你的唯一标识，建议联系客服处理。");
            helpList.add(d);
        }
        adapter.addData(helpList);
    }
}
